package com.yztc.xiami_app.ui.goods.presenter;

import android.util.Log;

import com.yztc.xiami_app.bean.goods.GoodsBean;
import com.yztc.xiami_app.ui.goods.model.GoodsModel;
import com.yztc.xiami_app.ui.goods.model.GoodsModelImpl;
import com.yztc.xiami_app.ui.goods.view.IGoodsView;

import java.util.Map;

import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
/**
 * Created by 周旭 on 2016/11/15.
 * "商品列表"Presenter的实现类
 */
public class GoodsPresenterImpl implements GoodsPresenter {

    private GoodsModel mGoodsModel;
    private IGoodsView mIGoodsView;

    public GoodsPresenterImpl(IGoodsView mIGoodsView) {
        mGoodsModel = new GoodsModelImpl();
        this.mIGoodsView = mIGoodsView;
    }

    @Override
    public void getGoodsData(Map<String,Object> params) {
        Observable<GoodsBean> cityBeanObservable = mGoodsModel.getGoodsBean(params);
        cityBeanObservable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<GoodsBean>() {
                    @Override
                    public void onCompleted() {}

                    @Override
                    public void onError(Throwable e) {
                        Log.i("tag","--------->onError");
                    }

                    @Override
                    public void onNext(GoodsBean goodsBean) {

                        Log.i("tag","--------->onNext");
                        mIGoodsView.showGoodsData(goodsBean);
                    }
                });
    }

}
